package com.ywjt.platformbusiness.my.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.cy.tablayoutniubility.FragPageAdapterVpNoScroll;
import com.cy.tablayoutniubility.TabAdapterNoScroll;
import com.cy.tablayoutniubility.TabLayoutNoScroll;
import com.cy.tablayoutniubility.TabMediatorVpNoScroll;
import com.cy.tablayoutniubility.TabNoScrollViewHolder;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseActivity;
import com.ywjt.platformbusiness.my.fragment.CouponFragment;

import java.util.ArrayList;
import java.util.List;


public class CouponActivity extends BaseActivity {
    private TabLayoutNoScroll tab1;
    private int status=0;//0 已领取 1 已过期
    private ViewPager viewpager;

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, CouponActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_mycoupon;
    }

    @Override
    protected void initView() {
        setTitleText("我的优惠券");
        tab1=findViewById(R.id.top_bar);
        viewpager=findViewById(R.id.viewpager);
        FragPageAdapterVpNoScroll<String> fragmentPageAdapter = new FragPageAdapterVpNoScroll<String>(getSupportFragmentManager(),7) {

            @Override
            public Fragment createFragment(String bean, int position) {
                switch (position) {
                    case 0://未使用
                        status = 0;
                        return CouponFragment.newInstance(status);
                    case 1://已使用
                        status =1;
                        return CouponFragment.newInstance(status);
                }
                return null;
            }

            @Override
            public void bindDataToTab(TabNoScrollViewHolder holder, int position, String bean, boolean isSelected) {
                TextView textView = holder.getView(R.id.tv);
                if (isSelected) {
                    textView.setTextColor(0xffFB222A);
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                } else {
                    textView.setTextColor(0xff333333);
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                }
                textView.setText(bean);
            }


            @Override
            public int getTabLayoutID(int position, String bean) {
                return R.layout.tab_item;
            }
        };
        TabAdapterNoScroll<String> tabAdapter = new TabMediatorVpNoScroll<String>(tab1, viewpager).setAdapter(fragmentPageAdapter);
        List<String> list = new ArrayList<>();
        list.add("已领取");
        list.add("已过期");
        fragmentPageAdapter.add(list);
        tabAdapter.add(list);

    }


    @Override
    protected void initData() {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int getTitleBarType() {
        return TITLEBAR_DEFAULT;
    }

}
